import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
import Main from '../views/Main.vue'
import Register from '../views/Register.vue'
import PrepaidView from '../views/charge/PrepaidView.vue'
import CommunityView from '../views/datacenter/CommunityView.vue'
import DeviceView from '../views/device/DeviceView.vue'
import NoticeView from '../views/property/NoticeView.vue'
import UserView from '../views/system/UserView.vue'




Vue.use(VueRouter)
//  防止连续点击多次路由报错---写到路由.js中
let routerPush = VueRouter.prototype.push;
let routerReplace = VueRouter.prototype.replace;
// push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/register',
    name: 'register',
    component: Register
  },

  {
    path: '/',
    redirect: "/main"
  },
  {
    path: '/main',
    component: Main,
    children: [
      {
        path: '/userView',
        name: 'userView',
        component: UserView
      },
      {
        path: '/communityView',
        name: 'communityView',
        component: CommunityView
      },
      {
        path: '/noticeView',
        name: 'noticeView',
        component: NoticeView
      },
      {
        path: '/prepaidView',
        name: 'prepaidView',
        component: PrepaidView
      },
      {
        path: '/deviceView',
        name: 'deviceView',
        component: DeviceView
      },


    ]

  },


  // {
  //   path: '/about',
  //   name: 'about',
  // route level code-splitting
  // this generates a separate chunk (about.[hash].js) for this route
  // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router